package com.fantasy.service.impl;

import com.fantasy.dao.OrderDao;
import com.fantasy.dao.impl.OrderDaoImpl;
import com.fantasy.entity.Order;
import com.fantasy.entity.Page;
import com.fantasy.entity.User;
import com.fantasy.service.OrderService;

import java.util.List;

public class OrderServiceImpl implements OrderService {
    private OrderDao orderDao=new OrderDaoImpl();
    @Override
    public int insert(Order order) {
        return orderDao.insert(order);
    }

    @Override
    public int delete(int id) {
        return orderDao.delete(id);
    }

    @Override
    public int update(Order order) {
        return orderDao.update(order);
    }

    @Override
    public Order queryByUserId(int userId) {
        return orderDao.queryByUserId(userId);
    }

    @Override
    public List<Order> queryAll() {
        return orderDao.queryAll();
    }

    @Override
    public Page<Order> pageQuery(int pageNo, int pageSize) {
        Page<Order> page=new Page();

        //设置开始页码
        page.setPageNo(pageNo);

        //设置当前页显示的数量
        page.setPageSize(pageSize);

        //设置当前页数据
        page.setItems(orderDao.queryForPageItems(pageNo,pageSize));

        //设置数据总数
        Integer totalCount = orderDao.queryForPageTotalCount();
        page.setPageTotalCount(totalCount);

        //设置总页码
        int count = totalCount / pageSize;
        if (totalCount % pageSize!=0){
            count+=1;
        }
        page.setPageTotal(count);

        return page;
    }
}
